package com.ruoyi.web.controller.finance;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.FmsCooperate;
import com.ruoyi.finance.service.IFmsCooperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 加盟 操作处理
 *
 * @author 夜雨
 */
@RestController
@RequestMapping("/finance/cooperate")
public class FmsCooperateController extends BaseController
{
    @Autowired
    private IFmsCooperateService cooperateService;

    /**
     * 获取加盟列表
     */
    @PreAuthorize("@ss.hasPermi('finance:cooperate:list')")
    @GetMapping("/list")
    public TableDataInfo list(FmsCooperate cooperate)
    {
        startPage();
        List<FmsCooperate> list = cooperateService.selectCooperateList(cooperate);
        return getDataTable(list);
    }

    /**
     * 根据加盟编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:cooperate:query')")
    @GetMapping(value = "/{cooperateId}")
    public AjaxResult getInfo(@PathVariable Long cooperateId)
    {
        return success(cooperateService.selectCooperateById(cooperateId));
    }

    /**
     * 新增加盟
     */
    @PreAuthorize("@ss.hasPermi('finance:cooperate:add')")
    @Log(title = "加盟", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody FmsCooperate cooperate)
    {
        cooperate.setCreateBy(getUsername());
        return toAjax(cooperateService.insertCooperate(cooperate));
    }

    /**
     * 修改加盟
     */
    @PreAuthorize("@ss.hasPermi('finance:cooperate:edit')")
    @Log(title = "加盟", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody FmsCooperate cooperate)
    {
        cooperate.setUpdateBy(getUsername());
        return toAjax(cooperateService.updateCooperate(cooperate));
    }

    /**
     * 删除加盟
     */
    @PreAuthorize("@ss.hasPermi('finance:cooperate:remove')")
    @Log(title = "加盟", businessType = BusinessType.DELETE)
    @DeleteMapping("/{cooperateIds}")
    public AjaxResult remove(@PathVariable Long[] cooperateIds)
    {
        return toAjax(cooperateService.deleteCooperateByIds(cooperateIds));
    }
}
